package com.yupi.springbootinit.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yupi.springbootinit.model.entity.Anonname;
import com.yupi.springbootinit.service.AnonnameService;
import com.yupi.springbootinit.mapper.AnonnameMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Random;

/**
* @author LENOVO
* @description 针对表【anonname】的数据库操作Service实现
* @createDate 2024-10-31 15:22:15
*/
@Service
public class AnonnameServiceImpl extends ServiceImpl<AnonnameMapper, Anonname>
    implements AnonnameService{

    @Resource
    private AnonnameMapper anonnameMapper;

    @Override
    public String getAnonname() {

        Random random = new Random();
        int index = random.nextInt(300);//生成五千以内的随机整数
        //从五千个匿名昵称中随机选择一个
        QueryWrapper<Anonname> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", index);
        Anonname selectedAnonname = anonnameMapper.selectOne(queryWrapper);
        return selectedAnonname.getAnonname(); // 请根据
    }
}




